import org.apache.spark.sql.SparkSession

object laz01 {
  def main(args: Array[String]): Unit = {
    val spark = SparkSession.builder()
      .appName("Word Frequency Count")
      .master("local[*]")
      .getOrCreate()

    val dataRDD = spark.sparkContext.textFile("data(5).txt")

    val resultRDD = dataRDD
      .map(_.split("\\\\00A")(2))
      .map(category => (category, 1))
      .reduceByKey(_ + _)

    resultRDD.collect().foreach { case (category, count) =>
      println(s"（$category，$count）")
    }

    spark.stop()
  }
}